package leetcode.biweekly.week96;

//Solution2Test
public class Solution2 {

	public long minOperations(int[] nums1, int[] nums2, int k) {
		int n = nums1.length;
		long add = 0, sub = 0;
		for (int i = 0; i < n; i++) {
			int n1 = nums1[i], n2 = nums2[i];
			if (n1 == n2) {
				continue;
			}
			if (k == 0 && n1 != n2) {
				return -1;
			}
			if (Math.abs(n1 - n2) % k != 0) {
				return -1;
			}
			if (n1 > n2) {
				sub += (n1 - n2) / k;
			} else {
				add += (n2 - n1) / k;
			}
		}
		if (add != sub) {
			return -1;
		}
		return add;
	}

}
